package com.ruoyi.bbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bbs.domain.BbsThread;
import com.ruoyi.bbs.service.IBbsThreadService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 主题Controller
 * 
 * @author saruri
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/thread")
public class BbsThreadController extends BaseController
{
    @Autowired
    private IBbsThreadService bbsThreadService;

    /**
     * 查询主题列表
     */
    @RequiresPermissions("bbs:thread:list")
    @GetMapping("/list")
    public TableDataInfo list(BbsThread bbsThread)
    {
        startPage();
        List<BbsThread> list = bbsThreadService.selectBbsThreadList(bbsThread);
        return getDataTable(list);
    }

    /**
     * 导出主题列表
     */
    @RequiresPermissions("bbs:thread:export")
    @Log(title = "主题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BbsThread bbsThread)
    {
        List<BbsThread> list = bbsThreadService.selectBbsThreadList(bbsThread);
        ExcelUtil<BbsThread> util = new ExcelUtil<BbsThread>(BbsThread.class);
        util.exportExcel(response, list, "主题数据");
    }

    /**
     * 获取主题详细信息
     */
    @RequiresPermissions("bbs:thread:query")
    @GetMapping(value = "/{tid}")
    public AjaxResult getInfo(@PathVariable("tid") Long tid)
    {
        return success(bbsThreadService.selectBbsThreadByTid(tid));
    }

    /**
     * 新增主题
     */
    @RequiresPermissions("bbs:thread:add")
    @Log(title = "主题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsThread bbsThread)
    {
        return toAjax(bbsThreadService.insertBbsThread(bbsThread));
    }

    /**
     * 修改主题
     */
    @RequiresPermissions("bbs:thread:edit")
    @Log(title = "主题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsThread bbsThread)
    {
        return toAjax(bbsThreadService.updateBbsThread(bbsThread));
    }

    /**
     * 删除主题
     */
    @RequiresPermissions("bbs:thread:remove")
    @Log(title = "主题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tids}")
    public AjaxResult remove(@PathVariable Long[] tids)
    {
        return toAjax(bbsThreadService.deleteBbsThreadByTids(tids));
    }
}
